import request from './request'

request.interceptor.request = (config) => {
	const token = uni.getStorageSync('token');
	if (token) {
		if (!config.header) {
			config.header = {}
		}
		config.header["token"] = token;
	}
	return config
};

request.interceptor.response = (res) => {
	let {
		data,
		statusCode,
		header
	} = res;
	switch (statusCode) {
		case 401:
			uni.navigateTo({
				url: "/pages/ucenter/login"
			});
			break;
		case 404:
			uni.navigateTo({
				url: "/pages/exception/exception?action=404"
			});
			break;
		case 500:
			uni.navigateTo({
				url: "/pages/exception/exception?action=500"
			});
			break;
		default:
			break;
	}
};


export default request;
